jQuery(document).ready(function() {
	
	var base_url = baseurl;

        var maitainumbercompare = getCookie("maitainumbercompare");

        if(maitainumbercompare=="2" || maitainumbercompare=="3") {
          jQuery("#add-another-device").hide();
		  jQuery(".compBox div:nth-of-type(3)").removeClass("bordRight");
	}

        if(maitainumbercompare=="0") {
          alert("Your comparison list is empty");
	}
	
	jQuery('.compare-sku1').click(function(){
	     var sku = jQuery(".compare-sku1").attr('id');
	     var maitaicompare1 = getCookie("maitaicompare1");
	     var maitaicompare2 = getCookie("maitaicompare2");
	     var maitainumbercompare = getCookie("maitainumbercompare");

	     if(maitainumbercompare=="1") {
	             
	       if(sku==maitaicompare1){
		 document.cookie="maitainumbercompare=" + "0" + "; path=/";
		 document.cookie="maitaicompare1=" + "" + "; path=/";
		 document.cookie="maitaicompare2=" + "" + "; path=/";
		 window.location=base_url + "gallery";
	       }	   

	     }
		
	     if(maitainumbercompare=="2") {
	       document.cookie="maitainumbercompare=" + "1" + "; path=/";
	       
	       if(sku==maitaicompare1){
		 document.cookie="maitaicompare1=" + maitaicompare2 + "; path=/";
		 document.cookie="maitaicompare2=" + "" + "; path=/";
	       } 

	       if(sku==maitaicompare2)
		 document.cookie="maitaicompare2=" + "" + "; path=/";
		 
	       window.location=base_url + "compare";
	     }
	     
		  
	}); 

	jQuery('.compare-sku2').click(function(){
	     var sku = jQuery(".compare-sku2").attr('id');
	     var maitaicompare1 = getCookie("maitaicompare1");
	     var maitaicompare2 = getCookie("maitaicompare2");
	     var maitainumbercompare = getCookie("maitainumbercompare");

	     if(maitainumbercompare=="1") {
	         
	       if(sku==maitaicompare1){
		 document.cookie="maitainumbercompare=" + "0" + "; path=/";
		 document.cookie="maitaicompare1=" + "" + "; path=/";
		 document.cookie="maitaicompare2=" + "" + "; path=/";
		 window.location=base_url + "gallery";
	       } 

	     }
		
	     if(maitainumbercompare=="2") {
	       document.cookie="maitainumbercompare=" + "1" + "; path=/";
	       
	       if(sku==maitaicompare1){
		 document.cookie="maitaicompare1=" + maitaicompare2 + "; path=/";
		 document.cookie="maitaicompare2=" + "" + "; path=/";
	       } 

	       if(sku==maitaicompare2)
		 document.cookie="maitaicompare2=" + "" + "; path=/";
	       
	       window.location=base_url + "compare";
	     }
		  
	}); 

	jQuery('.get-sku1').click(function(){
	     var sku = jQuery(".compare-sku1").attr('id');
		 var price1 = jQuery('#price1').text();
		 //price1 = price1.substring(4);
	     document.cookie="sku=" + sku + "; path=/";	
	     document.cookie="gadget=" + jQuery('#prodname1').text() + "; path=/"; 
	     document.cookie="price=" + price1 + "; path=/";
		 document.cookie="imgsrc=" + jQuery(".compare-img1").attr('src') + "; path=/";	
	     document.cookie="current_pos=" + "2" + "; path=/";		 
	}); 

	jQuery('.get-sku2').click(function(){
	     var sku = jQuery(".compare-sku2").attr('id');
	     var price2 = jQuery('#price2').text();
		 //price2 = price2.substring(4);
		 document.cookie="sku=" + sku + "; path=/";	
	     document.cookie="gadget=" + jQuery('#prodname2').text() + "; path=/"; 
	     document.cookie="price=" + price2 + "; path=/";
		 document.cookie="imgsrc=" + jQuery(".compare-img2").attr('src') + "; path=/";	
		 document.cookie="current_pos=" + "2" + "; path=/";
	}); 


});


function getCookie(cname)
{
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) 
  {
  var c = ca[i].replace(/\s/g, "");
  if (c.indexOf(name)==0) return c.substring(name.length,c.length);
  }
return "";
}